<%@ page import="com.wl.shixun5.*,java.util.*"%>
<%@ page import="com.wl.shixun5.dao.CartInfo_DAO" %>
<%@ page import="com.wl.shixun5.dao.OrderInfo_Orderdetail_DAO" %>
<%@ page import="com.wl.shixun5.info.CartInfo_BookInfo" %>
<%@ page import="com.wl.shixun5.info.OrderInfo" %>
<%@ page import="com.wl.shixun5.info.Orderdetail" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>2350300097 万朗</title>
</head>
<body>
<%
    request.setCharacterEncoding("UTF-8");
    String userId = (String)session.getAttribute("memberID");
    List<CartInfo_BookInfo> li = CartInfo_DAO.find(userId);
    
    // 获取订单信息
    String name = request.getParameter("name");
    String totalprice = request.getParameter("totalprice");
    String add = request.getParameter("add");
    String zip = request.getParameter("zip");
    String memo = request.getParameter("memo");
    
    // 创建订单
    String orderId = OrderInfo_Orderdetail_DAO.createOrderId();
    OrderInfo oi = new OrderInfo();
    oi.setOrderId(orderId);
    oi.setUserId(userId);
    oi.setReceiverName(name);
    oi.setReceiverAdd(add);
    oi.setReceiverZip(zip);
    oi.setOrderMemo(memo);
    oi.setOrderPrice(Float.parseFloat(totalprice));
    oi.setOrderDate(new java.sql.Date(System.currentTimeMillis()));
    oi.setIsSale(0);
    
    // 插入订单信息
    OrderInfo_Orderdetail_DAO.insertOrderInfo(oi);
    
    // 插入订单详细
    for(CartInfo_BookInfo cb:li) {
        Orderdetail od = new Orderdetail();
        od.setOrderId(orderId);
        od.setBookId(cb.getCi().getBookId());
        od.setBookCount(cb.getCi().getBookCount());
        OrderInfo_Orderdetail_DAO.insertOrderdetail(od);
    }
    
    // 清空购物车
    CartInfo_DAO.empty(userId);
%>

<p align="center"><strong><font size="6">订单提交成功</font></strong></p>
<p align="center"><strong>订单号：<%=orderId %></strong></p>
<p align="center"><strong>感谢您的购买！</strong></p>
<p align="center"><a href="booklist.jsp">继续购物</a>&nbsp;&nbsp;&nbsp;
    <a href="orderlist.jsp">查看我的订单</a></p>

</body>
</html>
